package com.ttbj.product.api.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ttbj.core.util.DtoTransitionUtils;
import com.ttbj.exception.WebException;
import com.ttbj.product.api.SalesmanFacade;
import com.ttbj.product.bean.dto.SalesmanDto;
import com.ttbj.salesman.bean.po.Salesman;
import com.ttbj.salesman.dao.SalesmanMapper;
import com.ttbj.util.ResultUtil;

@Service("salesmanFacade")
public class SalesmanFacadeImpl implements SalesmanFacade {
	
	@Autowired
	SalesmanMapper salesmanMapper = null;

	@Override
	public SalesmanDto findSalesman(SalesmanDto salesmanDto) {
		return salesmanMapper.getUser((Salesman)DtoTransitionUtils.trans(Salesman.class, salesmanDto));
	}

	@Override
	public void updateUser(SalesmanDto user) throws WebException {
		int result = salesmanMapper.updateUser((Salesman)DtoTransitionUtils.trans(Salesman.class, user));
		if ( 0 == result ){
			ResultUtil.throwExcepion(ResultUtil.createFail("messages", 912), "更新司机信息时出现错误");
		}
	}

	@Override
	public void addUser(SalesmanDto user) {
		salesmanMapper.insertSelective((Salesman)DtoTransitionUtils.trans(Salesman.class, user));
	}
	
	public void logout(SalesmanDto user){
		salesmanMapper.logout((Salesman)DtoTransitionUtils.trans(Salesman.class, user));
	}
}
